import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins";

export const pageListMixins = {
    mixins:[MescrollMixin],
    data(){
        return {
            //列表数据
            dataList: [],
            pageNo: 1,
            pageSize: 5,
        }
    },
    methods:{
        mescrollInit(mescroll) {
            this.mescroll = mescroll;
            //设置一些初始化参数
            this.mescroll.optUp.page = {num: this.pageNo, size: this.pageSize}
            this.mescroll.optUp.textNoMore = '-- 没有更多了 --'
        },
        /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
        async upCallback(page) {
            console.log("执行啦",page.num)
            this.pageNo = page.num
            this.pageSize = page.size
            if (page.num === 1) {
                this.dataList = []; //如果是第一页需手动制空列表
            }
            try {
                //TODO this.getDataList()需要自己实现
                let result = await this.getDataList()
                let {records, pages, total} = result
                this.mescroll.endByPage(total, pages)
                this.dataList = this.dataList.concat(records); //追加新数据
            } catch (e) {
                console.log("e", e)
            }
        },
    }
}
